<include file="common:__head__"/>
<div class="permissions-tabs">
    <a class="role tabs-bg" href="{:U('Agent/index')}">代理列表</a>
</div>
<div class="permissions-content">
    <form class="form-horizontal" id="to_agent" action="{:U('Agent/edit_agent')}" method="post">
        <div class="permissions-le">
            <span class="add-admin"><a href="javascript:history.go(-1)"></a>代理修改</span>
            <div class="add-admin-ipt">
                <span>代理姓名</span>
                <input type="text" class="w200" disabled value="{$agent['agent_name']}"/>
                <span class="noc_tips"></span>
            </div>
            <div class="add-admin-ipt">
                <span>手机号</span>
                <input type="text" class="w200" value="{$agent['mobile']}" disabled/>
                <span class="noc_tips"></span>
            </div>
            <div class="add-admin-ipt">
                <span>代理品牌</span>
                <select name="brand_id[]" id="brand" multiple="multiple" class="h80">
                    <foreach name="brands" item="brand">
                        <option value="{$brand['id']}" <?php if(in_array($brand['id'] ,$self_brands)){echo "selected";} ?>>{$brand['b_name']}</option>
                    </foreach>
                </select>
                <span class="noc_tips">按Ctrl多选</span>
            </div>
            <div class="add-admin-ipt">
                <span>上级代理</span>
                <input type="text" id="search_to" class="w100" style="margin-right:10px;">
                <select name="to_id" id="pid">
                    <option value="">请选择</option>
                    <option value="0">顶级代理</option>
                </select>
                <span class="noc_tips">左侧文本框搜索，右侧选择</span>
            </div>
            <div class="add-admin-ipt">
                <span>密码重置</span>
                <input type="text" class="w200" name="npwd"/>
                <span class="noc_tips">如需修改密码请填写</span>
            </div>

            <input type="hidden" name="agent_id" value="{$agent['agent_id']}"/>
            <div class="add-admin-ipt">
                <span></span>
                <a class="btn-lg btn-blue" id="submitBtn">保存</a>
            </div>
        </div>
    </form>
    <div class="permissions-ri">
        <a href="" class="permissions-help">帮助和服务</a>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        $('#submitBtn').click(function () {
            $("#to_agent").submit();
        });

        $("#search_to").keyup(function(){
            $aName = $(this).val();
            if($aName != ''){
                getAgentName();
            }else{
                return false;
            }
        });

        $("#search_to").change(function(){
            $aName = $(this).val();
            if($aName != ''){
                getAgentName();
            }else{
                return false;
            }
        });

        function getAgentName()
        {
            $.ajax({
                url: "{:U('Agent/searchAgent')}",
                type: "post",
                data: {aName : $aName},
                success: function (data)
                {
                    options = '<option value="0">顶级代理</option>';
                    if (data) {
                        $.each(data, function(k, v){
                            options += '<option value="'+ v.agent_id +'">'+ v.agent_name +'  '+v.mobile+'</option>';
                        });
                    }
                    $("#pid").html(options);
                }
            });
        }
    });
</script>
<include file="common:__foot__"/>